package com.moss.cloud.base.biz.controller;

import com.moss.cloud.base.api.model.from.BaseFrom;
import com.moss.cloud.base.api.model.from.SysDictFrom;
import com.moss.cloud.base.api.model.param.DictParam;
import com.moss.cloud.base.biz.service.ISysDictService;
import com.moss.cloud.common.core.constant.ServiceList;
import com.moss.cloud.common.core.model.Result;
import com.moss.cloud.common.security.annotation.SysLog;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 字典管理前端控制器
 *
 * @author 瑾年
 * @date 2023年11月21日
 */
@RestController
@RequestMapping(ServiceList.BASE + "/sysDict")
public class SysDictController {
    private final ISysDictService sysDictService;

    public SysDictController(ISysDictService sysDictService) {
        this.sysDictService = sysDictService;
    }
    /**
     * 字典树形结构数据查询
     *
     * @param dictParam
     * @return
     */
    @PostMapping("/dictTreeList")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "字典树形结构数据查询")
    public Result<?> dictTreeList(@RequestBody DictParam dictParam){
        return Result.success(sysDictService.dictTreeList(dictParam));
    }

    /**
     * 新增字典
     *
     * @param sysDictFrom
     * @return
     */
    @PostMapping("/saveDict")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "新增字典")
    public Result<?> saveDict(@RequestBody @Validated SysDictFrom sysDictFrom){
        return Result.success(sysDictService.saveDict(sysDictFrom));
    }

    /**
     * 编辑字典
     *
     * @param sysDictFrom
     * @return
     */
    @PostMapping("/updateDict")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "编辑字典")
    public Result<?> updateDict(@RequestBody @Validated SysDictFrom sysDictFrom){
        return Result.success(sysDictService.updateDict(sysDictFrom));
    }

    /**
     * 删除字典-物理删除
     *
     * @param baseFrom
     * @return
     */
    @PostMapping("/removeDict")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "删除字典-物理删除")
    public Result<?> removeDict(@RequestBody @Validated BaseFrom baseFrom){
        return Result.success(sysDictService.removeDict(baseFrom));
    }

    /**
     * 查询分组下的字典数据
     *
     * @param dictParam
     * @return
     */
    @PostMapping("/dictGroup")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "查询分组下的字典数据")
    public Result<?> dictGroup(@RequestBody DictParam dictParam){
        return Result.success(sysDictService.dictGroup(dictParam));
    }

    /**
     * 查询字典KEY的数据
     *
     * @param dictParam
     * @return
     */
    @PostMapping("/dictKey")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "查询字典KEY的数据")
    public Result<?> dictKey(@RequestBody DictParam dictParam){
        return Result.success(sysDictService.dictKey(dictParam));
    }

    /**
     * 加载字典数据
     *
     * @return
     */
    @PostMapping("/overload")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "加载字典数据")
    public Result<?> overload(){
        return Result.success(sysDictService.overload());
    }


}
